<?php
/**
 * OS CRM SYSTEM - An open source application development framework for PHP 4.3.2 or newer
 *
 * CLASS - LOGIN
 * 
 * @name      login
 * @package		OS CRM
 * @category  Class
 * @author		CRM SYSTEM Dev Team
 * @copyright	Copyright (c) 2010 - 2012, CRM SYSTEM
 * @since     Version 1.0
 * @filesource
 * @access    public 
 */

// ------------------------------------------------------------------------

class login extends Controller {
  
  /*common class varibale*/
  var $c 	= 'login';//current controler
	var $p_c = '';//parent controller
  
  /**
   * login  - constructor of the c;ass
   * 
   * @access public
   * @param  NA
   * @return void
   */
	function login()
	{
		parent::Controller();	
	}
	
  // ------------------------------------------------------------------------

  /**
   * index  - default function
   * 
   * @access public
   * @param  NA
   * @return void
   */
	function index()
	{
    $data = array();
    $data['frm_name']   = 'frmlogin';
    $data['frm_action'] = site_url( $this->c . '/ajax/check');
    //$this->_cheak_ip();
    __display('login', $data);
	} 
  
  /** 
	 * Logout
	 *
	 * @descp NA
	 * @access public
	 * @param  NA	 
	 * @return void
	 */
	function logout()
	{
		$this->session->unset_userdata('usr_info');
    $this->session->sess_destroy();
		redirect('login');
	}
	
  function _cheak_ip(){
    $ip = $this->input->ip_address();
    $qry = "SELECT `os_mem_id`, `os_mem_usr`, `os_mem_fname`, 
                    `os_mem_lname`, `os_mem_ins_code`, `os_mem_ins_name`, 
                    `os_mem_ins_email`, `os_mem_expiry`
              FROM ".TBL_MEMBERS."	
              WHERE	os_mem_ip_add LIKE '%".$ip."%'
              AND os_mem_status = '1'	
            ";
    //echo $qry;exit();
    $handle = $this->db->query($qry);
    $set_data = array();
    if($handle->num_rows() > 0)
    {
      $row = $handle->row_array();           
      /*write expriy validation code here*/

      $set_data = array(
            'usr_id' 		=> $row['os_mem_id'] ,
            'usr_name' 		=> $row['os_mem_usr'] ,
            'usr_email' 	=> $row['os_mem_ins_email'] ,
            'ins_name' 	=> $row['os_mem_ins_name'] ,								
            'ins_code' 	=> $row['os_mem_ins_code'] ,
            'usr_expiry' 	=> $row['os_mem_expiry'] ,
            'usr_grp_id' 	=> 0,
            'usr_grp_name' 	=> 'member' ,
            );	

      /*sety rights for users*/
      $set_data['jor_v'] = '';
      $set_data['jor_d'] = '';
      $set_data['art_v'] = '';
      $set_data['art_d'] = '';

      $qry_r = "SELECT * FROM ".TBL_MEMBERS_RIGHTS."	
                WHERE	os_mem_id = ".$row['os_mem_id']."";
      $rights = run_cust_qry($qry_r, TRUE);
      if($rights['num_rows'] > 0){
        $set_data['jor_v'] = $rights['list']['os_mem_rights_jor_v'];
        $set_data['jor_d'] = $rights['list']['os_mem_rights_jor_d'];
        $set_data['art_v'] = $rights['list']['os_mem_rights_art_v'];
        $set_data['art_d'] = $rights['list']['os_mem_rights_art_d'];
      }
      $this->session->set_userdata('usr_info',$set_data);	
      redirect('dashboard');
    }	
  }
}

/* End of file login.php */
/* Location: ./system/application/modules/login/controllers/login.php */